package com.qf.TimedTask;

import com.qf.util.JavaMailUtil;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author 何星宇
 * @version V1.0
 * @Date 2021/11/26 14:23
 */

@Component
@Slf4j
public class TimedTask {

    @Autowired
    private Channel channel;
    @Autowired
    private JavaMailUtil javaMailUtil;
    //定时任务，每三秒执行一次
    @Scheduled(cron = "0/3 * *  * * ?")
    public void timedTask() throws Exception {
        log.info("【监控框架-定时任务】 任务开始执行...");

        //统计每个队列中的消息数量
        AMQP.Queue.DeclareOk queue = channel.queueDeclarePassive("push_sms_report_topic");
        if (queue.getMessageCount()>5){
            javaMailUtil.sendMailForQueue("push_sms_report_topic", queue.getMessageCount());
        }
    }
}
